﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shipwire.Messages;

namespace Shipwire.Tests
{
    /// <summary>
    /// Summary description for RateTests
    /// </summary>
    [TestClass]
    public class RateTests
    {
        [TestMethod]
        public void Test_Example_Rate_Comes_Through()
        {
            IShipwireService service = TestShipwireAccount.CreateTestService();

            OrderRateRequest request = new OrderRateRequest
                {
                    Id = "12579",
                    AddressInfo = new AddressInfo
                        {
                            Name = new ShipwireName("Mr David Cameron"),
                            Address1 = "House of Commons",
                            Address2 = "",
                            City = "London",
                            State = "Greater London",
                            Zip = "SW1A 0PW",
                            Country = "UK"
                        },
                    Items = new OrderItem[] { new OrderItem { Code = TestShipwireAccount.TestProductCode, Quantity = 1, Num = "0" } }
                };

            var result = service.GetShippingEstimates(request);

            Assert.AreEqual("OK", result.Status);
            Assert.IsNull(result.ErrorMessage);

            Assert.IsTrue(result.Order.Quotes.Length > 0); // Ensure we have returned at least one result.
            
            // Cannot really keep these values the same, make sure they are at least set.
            foreach(var quote in result.Order.Quotes)
            {
                Assert.IsNotNull(quote.Warehouse);
                Assert.IsNotNull(quote.Service);
                Assert.IsNotNull(quote.Method);

                Assert.IsNotNull(quote.Cost);
                Assert.IsNotNull(quote.Cost.Currency);
                Assert.IsTrue(quote.Cost.Value > 0);

                Assert.IsNotNull(quote.DeliveryEstimate);
                Assert.IsNotNull(quote.DeliveryEstimate.Maximum);
                Assert.IsNotNull(quote.DeliveryEstimate.Maximum.Units);
                Assert.IsTrue(quote.DeliveryEstimate.Maximum.Value > 0);
                Assert.IsNotNull(quote.DeliveryEstimate.Minimum);
                Assert.IsNotNull(quote.DeliveryEstimate.Minimum.Units);
                Assert.IsTrue(quote.DeliveryEstimate.Minimum.Value > 0);
            }
        }
    }
}
